package com.cw.base.jeeyc.biz.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.base.jeeyc.api.dto.ApiDatabaseDto;
import com.cw.base.jeeyc.biz.converter.ApiDatabaseConverter;
import com.cw.base.jeeyc.biz.intf.ApiDatabaseQueryBiz;
import com.cw.base.jeeyc.dao.mapper.ApiDatabaseMapper;
import com.cw.base.jeeyc.dao.model.ApiDatabaseDo;

/**
 * 接口业务实现类
 *
 * @author chenw
 * @date 2019-08-24 10:59:29
 */
@Service
public class ApiDatabaseQueryBizImpl extends ServiceImpl<ApiDatabaseMapper, ApiDatabaseDo>
    implements ApiDatabaseQueryBiz {

    /**
     * 分页查询api数据库信息
     *
     * @param request 条件
     * @return PageInfo<ApiDatabaseDto>
     */
    @Override
    public Page<ApiDatabaseDto> selectPage(ApiDatabaseDto request) {
        Page page = page(new Page<>(request.getPageNum(), request.getPageSize()), ApiDatabaseConverter.buildWrapper(request));
        page.setRecords(ApiDatabaseConverter.doList2DtoList(page.getRecords()));
        return page;
    }

    /**
     * 查询api数据库信息详情信息
     *
     * @param request 条件
     * @return ApiDatabaseDto
     */
    @Override
    public ApiDatabaseDto queryDetail(ApiDatabaseDto request) {
        if (request == null) {
            return null;
        }
        return ApiDatabaseConverter.do2Dto(getBaseMapper().selectById(request.getId()));
    }

    /**
     * 根据条件查询api数据库信息
     *
     * @param request 条件
     * @return List<ApiDatabaseDto>
     */
    @Override
    public List<ApiDatabaseDto> queryList(ApiDatabaseDto request) {
        if (request == null) {
            return null;
        }
        return ApiDatabaseConverter.doList2DtoList(
            getBaseMapper().selectList(ApiDatabaseConverter.buildWrapper(request)));
    }

    /**
     * 根据key查询api数据库信息
     *
     * @param id
     * @return
     */
    @Override
    public ApiDatabaseDto selectByKey(Long id) {

        return ApiDatabaseConverter.do2Dto(getBaseMapper().selectById(id));
    }
}
